package com.farcloud.data.italent.util;

import com.farcloud.data.italent.common.enums.ExceptionCodeEnum;
import com.farcloud.data.italent.common.response.Response;

import java.io.Serializable;

public class ResponseUtil {

    public static <T extends Serializable> Response<T> build(ExceptionCodeEnum exceptionCode) {
        return Response.<T>builder().code(exceptionCode.getCode()).message(exceptionCode.getMessage()).build();
    }

    public static <T> Response<T> buildT(ExceptionCodeEnum exceptionCode) {
        return Response.<T>builder().code(exceptionCode.getCode()).message(exceptionCode.getMessage()).build();
    }


    public static <T extends Serializable> Response<T> build(int code, String message) {
        return Response.<T>builder().code(code).message(message).build();
    }

    public static <T extends Serializable> Response<T> build(int code, String message, T data) {
        return Response.<T>builder().code(code).message(message).data(data).build();
    }

    public static Response<Object> build(int code, String message, Object data) {
        return Response.builder().code(code).message(message).data(data).build();
    }

    public static Response buildException(int code, String message, Object data) {
        return Response.builder().code(code).message(message).data(data).build();
    }

    public static <T extends Serializable> Response<T> ok() {
        return build(ExceptionCodeEnum.SUCCESS);
    }

    public static <T extends Serializable> Response<T> ok(T data) {
        Response<T> response = build(ExceptionCodeEnum.SUCCESS);
        response.setData(data);
        return response;
    }

    public static <T> Response<T> ok(T data) {
        Response<T> response = buildT(ExceptionCodeEnum.SUCCESS);
        response.setData(data);
        return response;
    }

    public static <T extends Serializable> Response<T> error() {
        return build(ExceptionCodeEnum.FAIL);
    }

}
